package
{
	import core.MainManager;
	import core.modelManager.ModelManager;
	import core.sceneManager.SceneManager;
	import core.scriptManager.ScriptManager;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	
	import memory.MemoryRecovery;
	
	import view.ToolTip;
	/**
	 * 先加载策略文件，在加载数据库，数据库加载完毕后就初始化所有的管理者,最后，显示首页
	 */ 
	public class Main extends Sprite
	{
		public function Main()
		{
			this.addEventListener(Event.ADDED_TO_STAGE,on_added);
		}
		private function on_added(e:Event):void
		{
			MainManager.getInstance().stage=this.stage;
			SWFAddress.setTitle("广东海洋大学水生博物馆");
			init();
		}
		private function init():void
		{
			loadPoliFile();
			initDatabase();
		}
		/**
		 * 加载信任文件
		 */ 
		private function loadPoliFile():void
		{
		}
		/**
		 * 加载数据库
		 */ 
		private function initDatabase():void
		{
			var array:Array=[{key:"animate",path:"resource/xml/animate.xml"},
			                 {key:"flv",path:"resource/xml/flv.xml"},
			                 {key:"gehaiqingyun",path:"resource/xml/gehaiqingyun.xml"},
			                 {key:"item",path:"resource/xml/item.xml"},
			                 {key:"plugin",path:"resource/xml/plugin.xml"},
			                 {key:"pv3d",path:"resource/xml/pv3d.xml"},
			                 {key:"swf",path:"resource/xml/swf.xml"},
			                 {key:"scene",path:"resource/xml/scene.xml"}];
			ModelManager.getInstance().init(array,true);
			ModelManager.getInstance().addEventListener(ProgressEvent.PROGRESS,function on_progress(e:ProgressEvent):void{
			});
			ModelManager.getInstance().addEventListener(Event.COMPLETE,function on_complete(e:Event):void
			{
				MemoryRecovery.getInstance().gcFun(ModelManager.getInstance(),Event.COMPLETE,on_complete);
				MainManager.getInstance().scriptManager=ScriptManager.getInstance();//初始化脚本管理者
				MainManager.getInstance().sceneManager=SceneManager.getInstance();//初始化场景管理者
				SceneManager.getInstance().init(ModelManager.getInstance().getXml("scene"));
				SceneManager.getInstance().gotoScene(0);
				ToolTip.init(stage);
			});
		}
	}
}